package com.HuangJiaQing.www.service.impl;

import com.HuangJiaQing.www.dao.MarketersMapper;
import com.HuangJiaQing.www.dao.UserMapper;
import com.HuangJiaQing.www.model.Marketers;
import com.HuangJiaQing.www.model.User;
import com.HuangJiaQing.www.model.UserExample;
import com.HuangJiaQing.www.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HONOR
 * @date 2022/7/29 15:18
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MarketersMapper marketersMapper;
    public boolean registerUser(User user) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andUsernameEqualTo(user.getUsername());
        List<User> users = userMapper.selectByExample(userExample);
        if (users.isEmpty()) {
            userMapper.insertSelective(user);
            return true;
        } else {
            return false;
        }
    }

    public List<Marketers> userLogin() {
        List<Marketers> marketers = marketersMapper.selectByExample(null);
        return marketers;
    }
}
